package com.top.horizon.th1804app.utils;

import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.widget.Toast;

public class ToastUitl {

    private static Toast toast;



    public static void showToast(Context context,String message){
        if (TextUtils.isEmpty(message)) return;
        if (toast!=null){
            toast.cancel();
            toast=null;
        }
        toast=Toast.makeText(context,message,Toast.LENGTH_SHORT);
        toast.show();
    }
    public static void showLongToast(Context context,String message){
        if (TextUtils.isEmpty(message)) return;
        if (toast!=null){
            toast.cancel();
            toast=null;
        }
        toast=Toast.makeText(context,message,Toast.LENGTH_LONG);
        toast.show();
    }
    /**
     * 短时间中心显示Toast
     *
     * @param context
     * @param message
     */
    public static void showShortCenterToast(Context context, CharSequence message) {
        if (TextUtils.isEmpty(message)) return;
        if (toast != null) {
            toast.cancel();
            toast = null;
        }
        toast = Toast.makeText(context,
                message, Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }
}
